//注册页面 pages/register/register.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      var that = this;
      //调用应用实例的方法获取全局数据
      app.getUserInfo(function (userInfo) {
        //更新数据
        
        that.setData({
          userInfo: userInfo,
                 })
      });
      wx.getSystemInfo({
        success: function (info) {
          that.data.windowHeight = info.windowHeight;
          that.setData(that.data);
        }
      });

      wx.getStorage({
        key: 'trd_session',         
            success: function (res) {
              console.log(11);
            console.log(res);
              that.setData({
                key: res.data, 
              })
            },
            fail: function (res) {
              console.log(res)
            },
            complete: function () {
            }
          
      })
      }, 

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    formSubmit: function (e) {
       var that = this;
        var phone = /^1[34578]\d{9}$/;
        var flag = true;
        if (e.detail.value.tel == '') {
            this.ts('请输入您的手机号');
            flag = false;
        } else if (!phone.test(e.detail.value.tel)) {
            this.ts('请输入有效的手机号码');
            flag = false;
        }else if (e.detail.value.name == '') {
            this.ts('请输入您的姓名');
            flag = false;
        } 
        if (flag) {
            wx.request({
                url: 'https://xcx.chenjiudenanren.com/inter/Sy/regUser',
                header: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                method: 'POST',
                data: {
                    key: e.detail.value.key,
                    nickName: e.detail.value.nickName,
                    name: e.detail.value.name,
                    zf_id: e.detail.value.zf_id,
                    tel: e.detail.value.tel,
                },
                success: function (res) {
                    console.log(res.data);
                    that.tsOk(res.data);
                },
                fail: function (res) {
                    console.log(res)
                },
                complete: function () {
                }
            })
        }
    },
    ts: function (tsTxt) {
      wx.showToast({
        title: tsTxt,
        icon: 'none',
        duration: 2000
      })
    },
    tsOk: function (tsTxt) {
        wx.showToast({
            title: tsTxt,
            icon: 'none',
            duration: 2000
        });
        setTimeout(function () {
          wx.redirectTo({
            url: '../index/index'
          })
        }, 2000)
        
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})